package com.zxw.common.core.base.entity;

import cn.hutool.json.JSONObject;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;

@Data
public class BaseEntity implements Serializable {

    private static final long serialVersionUID = 4833233519829201367L;
    private Long companyId;

    /**
     * 创建人账号
     */
    private String createUserAccount;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss" )
    private LocalDateTime createTime;

    private Long createUserId;

    private Long lastUpdateUserId;

    private String lastUpdateUserAccount;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss" )
    private LocalDateTime lastUpdateTime;

    public BaseEntity() {
    }

    public BaseEntity(Long companyId, String createUserAccount, LocalDateTime createTime, Long createUserId, Long lastUpdateUserId, String lastUpdateUserAccount, LocalDateTime lastUpdateTime) {
        this.companyId = companyId;
        this.createUserAccount = createUserAccount;
        this.createTime = createTime;
        this.createUserId = createUserId;
        this.lastUpdateUserId = lastUpdateUserId;
        this.lastUpdateUserAccount = lastUpdateUserAccount;
        this.lastUpdateTime = lastUpdateTime;
    }

    public BaseEntity(JSONObject jsonObject) {
        this.companyId = jsonObject.getLong("companyId");
        this.createUserAccount = jsonObject.getStr("account");
        this.createTime = LocalDateTime.now();
        this.createUserId = jsonObject.getLong("userId");
        this.lastUpdateUserId = createUserId;
        this.lastUpdateUserAccount = createUserAccount;
        this.lastUpdateTime = createTime;
    }

}
